<template>
  <el-dialog
    class="findpass"
    title="找回密码"
    :visible.sync="show"
    width="600px"
    :before-close="close">
    <el-form label-width="80px" :model="formInline" class="demo-form-inline">
      <el-form-item label="账号">
        <el-input v-model="formInline.username" placeholder="请输入找回帐号"></el-input>
      </el-form-item>
      <el-form-item label="身份证号">
        <el-input v-model="formInline.idNumb" placeholder="请输入注册身份证号"></el-input>
      </el-form-item>
      <el-form-item label="手机号码">
        <el-input v-model="formInline.mobile" placeholder="请输入注册手机号码"></el-input>
      </el-form-item>
      <el-form-item v-show="passinput" label="新密码">
        <el-input v-model="formInline.password" placeholder="请输入新密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" v-if="yanzheng" @click="onSubmit(0)">验证信息</el-button>
        <el-button type="primary" v-if="!yanzheng" @click="onSubmit(1)">重置密码</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script type="text/ecmascript-6">
export default {
  props: {
    show: Boolean
  },
  data() {
    return {
      yanzheng: true,
      passinput: false,
      formInline: {
        username: null,
        idNumb: null,
        mobile: null,
        password: null
      }
    };
  },
  methods: {
    onSubmit(val) {
      if (val === 0) {
        this.$http
          .get("/common/user/details/check", {
            params: this.formInline
          })
          .then(res => {
            if (res.data.success) {
              this.yanzheng  = !this.yanzheng
              this.passinput = true;
              this.$message.success('验证成功！请设置密码！')
            } else {
              this.$message.error('信息有误，请确认帐号信息！')
            }
          });
      } else {
        let data = this.formInline;
        this.$http.put("/common/user/modify/pw", data).then(res => {
          if(res.data.success) {
            this.$message.success('重置成功！')
            this.close()
          }
        });
      }
    },
    close() {
      this.$emit("close");
    }
  },
  components: {}
};
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
